home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / rewrite / RewriteSuppo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  2.6 KB  |  91 lines

  1. /* ----------------------------------------------------------------
  2.  *   FILE
  3.  *    RewriteSupport.c
  4.  *    
  5.  *   NOTES
  6.  *
  7.  *   IDENTIFICATION
  8.  * $Header: /private/postgres/src/rewrite/RCS/RewriteSupport.c,v 2.6 1991/11/12 23:22:32 mer Exp $
  9.  * ----------------------------------------------------------------
  10.  */
  11.  
  12. #include "catalog/catname.h"
  13. #include "catalog/pg_rewrite.h"
  14. #include "utils/rel.h"            /* Relation, RelationData ... */
  15. #include "catalog/syscache.h"        /* for SearchSysCache */
  16. #include "utils/builtins.h"        /* for textout */
  17. #include "utils/log.h"                /* for elog */
  18. /* 
  19.  * RuleIdGetActionInfo
  20.  *
  21.  * given a rule oid, look it up and return 
  22.  * '(rule-event-qual (rule-parsetree_list))
  23.  *
  24.  */
  25.  
  26. List
  27. RuleIdGetActionInfo ( ruleoid , instead_flag)
  28.      OID ruleoid;
  29.      int *instead_flag;
  30. {
  31.     HeapTuple         ruletuple;
  32.     char         *ruleaction = NULL;
  33.     bool        action_is_null = false;
  34.     bool        instead_is_null = false;
  35.     Relation         ruleRelation = NULL;
  36.     TupleDescriptor    ruleTupdesc = NULL;
  37.     List            ruleparse = NULL;
  38.     char        *rule_evqual_string = NULL;
  39.     List        rule_evqual = NULL;
  40.     List        i = NULL;
  41.     int  instead;
  42.     ruleRelation = amopenr (RewriteRelationName);
  43.     ruleTupdesc = RelationGetTupleDescriptor(ruleRelation);
  44.     ruletuple = SearchSysCacheTuple ( RULOID,  ruleoid );
  45.     if (ruletuple == NULL)
  46.     elog(WARN, "rule %d isn't in rewrite system relation");
  47.     ruleaction = amgetattr ( ruletuple, InvalidBuffer, Anum_pg_rewrite_action, 
  48.                 ruleTupdesc , &action_is_null ) ;
  49.     rule_evqual_string = amgetattr (ruletuple, InvalidBuffer, 
  50.                     Anum_pg_rewrite_ev_qual, 
  51.                     ruleTupdesc , &action_is_null ) ;
  52.     *instead_flag = (int) amgetattr (ruletuple, InvalidBuffer, 
  53.                     Anum_pg_rewrite_is_instead, 
  54.                     ruleTupdesc , &instead_is_null ) ;
  55.     ruleaction = textout ((struct varlena *)ruleaction );
  56.     rule_evqual_string = textout((struct varlena *)rule_evqual_string);
  57.  
  58.     ruleparse = (List)StringToPlan(ruleaction);
  59.     rule_evqual = (List)StringToPlan(rule_evqual_string);
  60.  
  61.     if ( action_is_null ) {
  62.     printf ("action is empty !!!\n");
  63.     return ( LispNil );
  64.     } else {
  65.     foreach ( i , ruleparse ) {
  66. #ifdef DEBUG
  67. /*        Print_parse ( CAR(i) ); */
  68. #endif
  69.     }
  70.     }
  71.     amclose ( ruleRelation );
  72.     return (lispCons(rule_evqual,ruleparse));
  73. }
  74.  
  75. char *
  76. OperOidGetName ( oproid )
  77.      oid oproid;
  78. {
  79.     HeapTuple oprtuple = NULL;
  80.     OperatorTupleForm opform = NULL;
  81.  
  82.     oprtuple = SearchSysCacheTuple ( OPROID, oproid );
  83.     if ( oprtuple ) {
  84.     opform = (OperatorTupleForm)GETSTRUCT(oprtuple);
  85.     return ( (char *)&(opform->oprname));
  86.     } else {
  87.     return ("bogus-operator");
  88.     }
  89.     /*NOTREACHED*/
  90. }
  91.